<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="生产任务单号">
        <el-input v-model="queryParams.taskNo" placeholder="请输入生产任务单号"></el-input>
      </el-form-item>

      <el-form-item label="任务日期">
        <el-date-picker type="daterange" v-model="queryParams.taskDate" range-separator="至" start-placeholder="开始日期"
          end-placeholder="结束日期" clearable style="width: 240px" />
      </el-form-item>

      <el-form-item label="合同号">
        <el-input v-model="queryParams.contractNo" placeholder="请输入合同号"></el-input>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>

    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" size="mini" :disabled="single" @click="handleProcurement">生成采购单</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="warning" size="mini" :disabled="single" @click="handleDispatch">生成派工单</el-button>
      </el-col>

    </el-row>

    <el-tooltip placement="top">
      <div slot="content">点击任意一行列，即可在下方查看任务单明细记录</div>
      <el-table :data="taskDateList" v-loading="loading" @selection-change="handleSelectionChange" :row-class-name="rowClassName" @row-click="showTab">
        <el-table-column align="center" type="selection" width="55"></el-table-column>
        <el-table-column align="center" label="生成任务单号" prop="taskNo"></el-table-column>
        <el-table-column align="center" label="任务日期" prop="taskDate"></el-table-column>
        <el-table-column align="center" label="任务计划开始日期" prop="planStartDate"></el-table-column>
        <el-table-column align="center" label="任务计划结束日期" prop="planEndDate"></el-table-column>
        <el-table-column align="center" label="合同号" prop="contractNo"></el-table-column>
        <el-table-column align="center" label="备注" prop="remark"></el-table-column>
        <el-table-column label="审核状态" prop="status"></el-table-column>
        <el-table-column label="操作" width="150" fixed="right" align="center">
          <template slot-scope="scope">
            <el-button type="text" size="mini" @click="handleDetail(scope.row)">反审核</el-button>
            <el-button type="text" size="mini" @click="handleReview(scope.row)">审核</el-button>
            <el-button type="text" size="mini" @click="handleUpdateTask(scope.row)">修改</el-button>
            <el-button type="text" size="mini" @click="handleDeleteTask(scope.row)">删除</el-button>
            <el-button type="text" size="mini" @click="handleView(scope.row)">查看订单</el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-tooltip>

    <pagination :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList"
      :total="taskDateList.length" />

    <el-tabs v-model="activeName" v-if="showCard">
      <el-tab-pane name="first">
        <h2 align="center">{{ taskNo }}任务单明细</h2>
        <el-table :data="taskDetailData" v-loading="loadingTaskDetail">
          <el-table-column label="产品描述" align="center">
            <el-table-column prop="code" label="代号" align="center" />
            <el-table-column prop="name" label="名称" align="center" />
            <el-table-column prop="Spec" label="规格" align="center" />
            <el-table-column prop="customerNo" label="客户货号" align="center" />
            <el-table-column prop="productType" label="产品类型" align="center" />
          </el-table-column>
          <el-table-column prop="productAttributes" label="产品属性" align="center" />
          <el-table-column prop="color" label="颜色" align="center" />
          <el-table-column prop="weight" label="单重" align="center" />
          <el-table-column prop="marking" label="光粉型号" align="center" />
          <el-table-column prop="stuff" label="原料型号" align="center" />
          <el-table-column align="center" label="磨具货号" prop="sharpenerType"></el-table-column>
          <el-table-column align="center" label="磨数" prop="sharpenerNumber"></el-table-column>
          <el-table-column prop="stitch" label="贴花方式" align="center" />
          <el-table-column align="center" label="预估生成数量" prop="estimateQuantity"></el-table-column>
          <el-table-column align="center" label="宽放比例" prop="wideRatio"></el-table-column>
          <el-table-column align="center" label="包装要求" prop="packageRequirements"></el-table-column>
          <el-table-column align="center" label="称粉重量" prop="brandingWeight"></el-table-column>
          <el-table-column align="center" label="班产量" prop="batchQuantity"></el-table-column>
          <el-table-column align="center" width="150" label="操作" fixed="right">
            <template slot-scope="scope">
              <el-button type="text" size="mini" @click="handleTaskDetailUpdate(scope.row)">修改</el-button>
              <el-button type="text" size="mini" @click="handleTaskDetailDelete(scope.row)">删除</el-button>
              <el-button type="text" size="mini" @click="handleViewOrder(scope.row)">查看订单详细</el-button>
            </template>
          </el-table-column>
        </el-table>
      </el-tab-pane>
    </el-tabs>

    <el-dialog :title="titleTap" :visible.sync="openTap" width="1000px" append-to-body>
      <el-tabs v-model="activeNameComment" v-if="showCard">
        <el-tab-pane label="订单明细" name="first">
          <h2 align="center">{{ orderNo }}订单明细</h2>

          <!-- <el-row :gutter="10">
          <el-col :span="1.5">
            <el-button type="primary" size="mini" @click="handleAddComm">新增明细</el-button>
            <el-button type="info" size="mini" @click="handleCopyHistoryOrderComm">复制历史订单明细</el-button>
          </el-col>
        </el-row> -->

          <el-table :data="commdate">
            <el-table-column prop="id" label="序号" align="center" />
            <el-table-column label="产品描述" align="center">
              <el-table-column prop="code" label="代号" align="center" />
              <el-table-column prop="name" label="名称" align="center" />
              <el-table-column prop="Spec" label="规格" align="center" />
              <el-table-column prop="productType" label="产品类型" align="center" />
            </el-table-column>
            <el-table-column prop="productAttributes" label="产品属性" align="center" />
            <el-table-column prop="color" label="颜色" align="center" />
            <el-table-column prop="weight" label="单重" align="center" />
            <el-table-column prop="stitch" label="贴花方式" align="center" />
            <el-table-column prop="brand" label="商标" align="center" />
            <el-table-column prop="amount" label="装箱数" align="center" />
            <el-table-column prop="Mweight" label="毛重" align="center" />
            <el-table-column prop="netWeight" label="净重" align="center" />
            <el-table-column prop="grossWeight" label="体积" align="center" />
            <el-table-column prop="expiryDate" label="交货日期" align="center" />
            <el-table-column label="USD" align="center">
              <el-table-column prop="usdPrice" label="单价(USD)" align="center" />
              <el-table-column prop="usdAmount" label="金额(USD)" align="center" />
            </el-table-column>
            <el-table-column prop="deliveryDate" label="评审交期" align="center" />
            <el-table-column prop="sendGoods" label="已发货数" align="center" />
            <el-table-column prop="outbound" label="已出库数" align="center" />
            <!-- <el-table-column label="操作" width="150" fixed="right"  align="center" >
            <template slot-scope="scope">
              <el-button type="text" size="mini" @click="handleProductAttributes(scope.row)">设置产品属性</el-button>
              <el-button type="text" size="mini" @click="handleUpdateComm(scope.row)">修改</el-button>
              <el-button type="text" size="mini" @click="handleDeleteComm(scope.row)">删除</el-button>
            </template>
          </el-table-column> -->
          </el-table>
        </el-tab-pane>
        <el-tab-pane label="订单明细要求" name="second">
          <el-row :gutter="20">
            <splitpanes :horizontal="this.$store.getters.device === 'mobile'" class="default-theme">
              <pane size="32">
                <el-tooltip placement="top">
                  <div slot="content">单击任意一行列即可查看详情订单要求</div>
                  <el-table :data="commdate" @row-click="handleDetailClick">
                    <el-table-column prop="code" label="代号" align="center" />
                    <el-table-column prop="name" label="名称" align="center" />
                    <el-table-column prop="Spec" label="规格" align="center" />
                    <el-table-column prop="customerNo" label="客户货号" align="center" />
                    <el-table-column prop="productType" label="产品类型" align="center" />
                  </el-table>
                </el-tooltip>
              </pane>
              <pane size="64">
                <el-row :gutter="10" class="mb8">
                  <el-col :push='1' :span="1.5">
                    <el-button type="primary" size="mini" @click="handleAddSave">保存</el-button>
                  </el-col>
                </el-row>
                <el-form ref="formOrderDetail" :model="formOrderDetail" label-width="80px">
                  <el-row>
                    <el-col :span="12">
                      <el-form-item label="产品组成" prop="productComposition">
                        <el-tooltip content="针对所有明细产品同样设置" placement="top">
                          <el-button type="primary" size="mini" icon="el-icon-s-tools"
                            @click="applyToAllDetails('产品组成','productComposition',formOrderDetail.productComposition)"></el-button>
                        </el-tooltip>
                        <el-input type="textarea" v-model="formOrderDetail.productComposition"></el-input>
                      </el-form-item>
                    </el-col>
                    <el-col :span="12">
                      <el-form-item label="包装要求" prop="packageRequirements">
                        <el-tooltip content="针对所有明细产品同样设置" placement="top">
                          <el-button type="primary" size="mini" icon="el-icon-s-tools"
                            @click="applyToAllDetails('包装要求','packageRequirements',formOrderDetail.packageRequirements)"></el-button>
                        </el-tooltip>
                        <el-input type="textarea" v-model="formOrderDetail.packageRequirements"></el-input>
                      </el-form-item>
                    </el-col>
                  </el-row>

                  <el-row>
                    <el-col :span="12">
                      <el-form-item label="品质要求" prop="qualityRequirements">
                        <el-tooltip content="针对所有明细产品同样设置" placement="top">
                          <el-button type="primary" size="mini" icon="el-icon-s-tools"
                            @click="applyToAllDetails('品质要求','qualityRequirements',formOrderDetail.qualityRequirements)"></el-button>
                        </el-tooltip>
                        <el-input type="textarea" v-model="formOrderDetail.qualityRequirements"></el-input>
                      </el-form-item>
                    </el-col>
                    <el-col :span="12">

                      <el-form-item label="英文包装要求" prop="englishPackageRequirements">
                        <el-tooltip content="针对所有明细产品同样设置" placement="top">
                          <el-button type="primary" size="mini" icon="el-icon-s-tools"
                            @click="applyToAllDetails('英文包装要求','englishPackageRequirements',formOrderDetail.englishPackageRequirements)"></el-button>
                        </el-tooltip>
                        <el-input type="textarea" v-model="formOrderDetail.englishPackageRequirements"></el-input>
                      </el-form-item>
                    </el-col>
                  </el-row>

                  <el-row>
                    <el-col :span="12">
                      <el-form-item label="封口方式" prop="sealingMethod">
                        <el-tooltip content="针对所有明细产品同样设置" placement="top">
                          <el-button type="primary" size="mini" icon="el-icon-s-tools"
                            @click="applyToAllDetails('封口方式','sealingMethod',formOrderDetail.sealingMethod)"></el-button>
                        </el-tooltip>
                        <el-input type="textarea" v-model="formOrderDetail.sealingMethod"></el-input>
                      </el-form-item>
                    </el-col>
                    <el-col :span="12">
                      <el-form-item label="打包方式" prop="packingMethod">
                        <el-tooltip content="针对所有明细产品同样设置" placement="top">
                          <el-button type="primary" size="mini" icon="el-icon-s-tools"
                            @click="applyToAllDetails( '打包方式','packingMethod',formOrderDetail.packingMethod)"></el-button>
                        </el-tooltip>
                        <el-input type="textarea" v-model="formOrderDetail.packingMethod"></el-input>
                      </el-form-item>
                    </el-col>
                  </el-row>

                  <el-row>
                    <el-col :span="12">
                      <el-form-item label="唛头" prop="marking">
                        <el-tooltip content="针对所有明细产品同样设置" placement="top">
                          <el-button type="primary" size="mini" icon="el-icon-s-tools"
                            @click="applyToAllDetails( '唛头','marking',formOrderDetail.marking)"></el-button>
                        </el-tooltip>
                        <el-input type="textarea" v-model="formOrderDetail.marking"></el-input>
                      </el-form-item>
                    </el-col>
                    <el-col :span="12">
                      <el-form-item label="纸箱材质" prop="paperMaterial">
                        <el-tooltip content="针对所有明细产品同样设置" placement="top">
                          <el-button type="primary" size="mini" icon="el-icon-s-tools"
                            @click="applyToAllDetails( '纸箱材质','paperMaterial',formOrderDetail.paperMaterial)"></el-button>
                        </el-tooltip>
                        <el-input type="textarea" v-model="formOrderDetail.paperMaterial"></el-input>
                      </el-form-item>
                    </el-col>
                  </el-row>


                </el-form>
              </pane>
            </splitpanes>
          </el-row>
        </el-tab-pane>
        <el-tab-pane label="产品图片" name="third">
          <el-row :gutter="20">
            <splitpanes :horizontal="this.$store.getters.device === 'mobile'" class="default-theme">
              <pane size="48">
                <el-table :data="commdate" @row-click="handleImgClick">
                  <el-table-column prop="code" label="代号" align="center" />
                  <el-table-column prop="name" label="名称" align="center" />
                  <el-table-column prop="Spec" label="规格" align="center" />
                  <el-table-column prop="customerNo" label="客户货号" align="center" />
                  <el-table-column prop="productType" label="产品类型" align="center" />
                </el-table>
              </pane>
              <pane size="48">
                <el-form ref="formImg" disabled :model="formImg" label-width="80px">
                  <el-form-item prop="img">
                    <ImageUpload v-model="img" />
                  </el-form-item>
                </el-form>
              </pane>
            </splitpanes>
          </el-row>
        </el-tab-pane>
        <el-tab-pane label="物料清单设置" name="fourth">
          <el-row :gutter="20">
            <splitpanes :horizontal="this.$store.getters.device === 'mobile'" class="default-theme">
              <pane size="32">
                <el-table :data="commdate" @row-click="handleBOMClick">
                  <el-table-column prop="code" label="代号" align="center" />
                  <el-table-column prop="name" label="名称" align="center" />
                  <el-table-column prop="Spec" label="规格" align="center" />
                  <el-table-column prop="customerNo" label="客户货号" align="center" />
                  <el-table-column prop="productType" label="产品类型" align="center" />
                  <!-- <el-table-column label="操作" fixed="right"  align="center" >
                    <template slot-scope="scope">
                      <el-button type="text" size="mini" @click="handleAddBOM(scope.row)">生成订单BOM</el-button>
                    </template>
                  </el-table-column> -->
                </el-table>
              </pane>
              <pane size="64">
                <el-row>
                  <el-col :span="1.5">
                    <el-button type="primary" size="mini" @click="handleAddMaterial">新增物料</el-button>
                  </el-col>
                </el-row>
                <el-table :data="materialData">
                  <el-table-column label="物品描述" align="center">
                    <el-table-column prop="code" label="代号" align="center" />
                    <el-table-column prop="name" label="名称" align="center" />
                    <el-table-column prop="quantity" label="材质" align="center" />
                    <el-table-column prop="unit" label="单位" align="center" />
                  </el-table-column>
                  <el-table-column label="尺寸" align="center">
                    <el-table-column prop="length" label="长" align="center" />
                    <el-table-column prop="width" label="宽" align="center" />
                    <el-table-column prop="height" label="高" align="center" />
                  </el-table-column>
                  <el-table-column prop="productAttributes" label="产品属性" align="center" />
                  <el-table-column prop="color" label="颜色" align="center" />
                  <el-table-column prop="weight" label="单重" align="center" />
                  <el-table-column prop="stitch" label="用量" align="center" />
                  <el-table-column prop="deputiUnits" label="副单位" align="center" />
                  <el-table-column prop="brand" label="花色" align="center" />
                  <el-table-column prop="calculationDirection" label="计算方向" align="center" />
                  <el-table-column label="操作" fixed="right" align="center">
                    <template slot-scope="scope">
                      <el-button type="text" size="mini" @click="handleEditMaterial(scope.row)">修改</el-button>
                      <el-button type="text" size="mini" @click="handleDeleteMaterial(scope.row)">删除</el-button>
                    </template>
                  </el-table-column>
                </el-table>
              </pane>
            </splitpanes>
          </el-row>
        </el-tab-pane>
        <el-tab-pane label="订单附件" name="fifth">
          <el-row :gutter="20">
            <splitpanes :horizontal="this.$store.getters.device === 'mobile'" class="default-theme">
              <pane size="64">
                <!-- <el-row :gutter="10" class="mb8">
                <el-col :span="1.5">
                  <el-button type="primary" size="mini" @click="handleAddFile">添加附件</el-button>
                </el-col>
              </el-row> -->
                <el-table :data="fileDate">
                  <el-table-column prop="fileNo" label="附件主题" align="center" />
                  <el-table-column prop="fileName" label="附件名称" align="center" />
                  <el-table-column prop="filePath" label="附件路径" align="center">
                    <template slot-scope="scope">
                      <el-button size="mini" type="text" @click="handleDownload1(scope.row)">查看附件</el-button>
                    </template>
                  </el-table-column>
                  <el-table-column prop="fileType" label="附件说明" align="center" />
                  <!--  <el-table-column label="附件操作" fixed="right"  align="center" >
                    <template slot-scope="scope">
                      <el-button type="text" size="mini" @click="handleFileDownload(scope.row)">下载</el-button>
                      <el-button type="text" size="mini" @click="handleFileDelete(scope.row)">删除</el-button>
                    </template>
                  </el-table-column> -->
                </el-table>
              </pane>
            </splitpanes>
          </el-row>
        </el-tab-pane>
        <el-tab-pane label="变更情况" name="sixth">
          <el-row :gutter="20">
            <splitpanes :horizontal="this.$store.getters.device === 'mobile'" class="default-theme">
              <pane size="64">
                <!--  <el-row :gutter="10" class="mb8">
                <el-col :span="1.5">
                  <el-button type="primary" size="mini" @click="handleAdd">添加变更</el-button>
                </el-col>
              </el-row> -->
                <el-table :data="changeDate">
                  <el-table-column prop="changeNumber" label="变更次数" align="center" />
                  <el-table-column prop="changeNo" label="变更单号" align="center" />
                  <el-table-column prop="changeDate" label="变更日期" align="center" />
                  <el-table-column prop="changeModifier" label="变更人" align="center" />
                  <el-table-column prop="changeContent" label="变更内容" align="center" />
                  <!-- <el-table-column label="变更操作" fixed="right"  align="center" >
                    <template slot-scope="scope">
                      <el-button type="text" size="mini" @click="handleEditChange(scope.row)">修改</el-button>
                      <el-button type="text" size="mini" @click="handleDeleteChange(scope.row)">删除</el-button>
                    </template>
                  </el-table-column> -->
                </el-table>
              </pane>
            </splitpanes>
          </el-row>
        </el-tab-pane>

      </el-tabs>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="openTap = false">关闭</el-button>
      </div>

    </el-dialog>

    <!-- 订单明细要求 -->
    <el-dialog :title="titleOrderDetail" :visible.sync="openOrderDetail" width="800px" append-to-body>
      <el-form ref="formOrderDetail" :model="formOrderDetail" label-width="80px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="产品组成" prop="productComposition">
              <el-input type="textarea" v-model="formOrderDetail.productComposition"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="包装要求" prop="packageRequirements">
              <el-input type="textarea" v-model="formOrderDetail.packageRequirements"></el-input>
            </el-form-item>
          </el-col>

        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="品质要求" prop="qualityRequirements">
              <el-input type="textarea" v-model="formOrderDetail.qualityRequirements"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="英文包装要求" prop="englishPackageRequirements">
              <el-input type="textarea" v-model="formOrderDetail.englishPackageRequirements"></el-input>
            </el-form-item>
          </el-col>
        </el-row>


      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFormOrderDetail">确定</el-button>
        <el-button @click="cancelOrderDetail">取消</el-button>
      </div>
    </el-dialog>

    <!-- 生成订单BOM弹窗 -->
    <el-dialog :title="titleBOM" :visible.sync="openBOM" width="800px" append-to-body>
      <el-form ref="formBOM" :model="formBOM" label-width="80px">
        <el-row>
          <el-col :span="8">
            <el-form-item label="光粉" prop="lightFinger">
              <el-checkbox v-model="formBOM.lightFinger"></el-checkbox>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="代号" prop="lightFingerCode">
              <el-input v-model="formBOM.lightFingerCode" placeholder="请输入光粉代号"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="克重" prop="lightFingerWeight">
              <el-input v-model="formBOM.lightFingerWeight"></el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="8">
            <el-form-item label="原料" prop="rawMaterial">
              <el-checkbox v-model="formBOM.rawMaterial"></el-checkbox>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="代号" prop="rawMaterialCode">
              <el-input v-model="formBOM.rawMaterialCode" placeholder="请输入光粉代号"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="克重" prop="rawMaterialWeight">
              <el-input v-model="formBOM.rawMaterialWeight"></el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="花纸" prop="paper">
              <el-checkbox v-model="formBOM.paper"></el-checkbox>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="花纸" prop="paperCode">
              <el-slelect v-model="formBOM.paperCode" placeholder="请选择花纸">
                <el-option label="MF115#" value="MF115#"></el-option>
                <el-option label="MF118#" value="MF118#"></el-option>
                <el-option label="2484#" value="2484#"></el-option>
                <el-option label="TL218#" value="TL218#"></el-option>
                <el-option label="2479#" value="2479#"></el-option>
              </el-slelect>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="纸箱" prop="box">
              <el-checkbox v-model="formBOM.box"></el-checkbox>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="具体纸箱" prop="boxCode">
              <el-input v-model="formBOM.boxCode" placeholder="请输入具体纸箱(长*宽*高)"></el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>

          <el-col :span="8">
            <el-form-item label="条码" prop="barcode">
              <el-checkbox v-model="formBOM.barcode"></el-checkbox>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="OPP袋" prop="oppBag">
              <el-checkbox v-model="formBOM.oppBag"></el-checkbox>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="PE袋" prop="peBag">
              <el-checkbox v-model="formBOM.peBag"></el-checkbox>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="说明书" prop="instruction">
              <el-checkbox v-model="formBOM.instruction"></el-checkbox>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="彩标" prop="colorMark">
              <el-checkbox v-model="formBOM.colorMark"></el-checkbox>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="白纸" prop="whitePaper">
              <el-checkbox v-model="formBOM.whitePaper"></el-checkbox>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">

        <span style="margin-right: 120px;">
          <el-checkbox v-model="formBOM.createBom">是否对辅料建档</el-checkbox>
        </span>

        <el-button type="primary" @click="handleSubmitBOM">确定</el-button>
        <el-button @click="colseBOM">取消</el-button>
      </div>
    </el-dialog>

    <!-- 物料清单弹窗 -->
    <el-dialog :title="titleMaterialList" :visible.sync="openMaterial" width="800px" append-to-body>
      <el-form ref="formMaterialList" :model="formMaterialList" label-width="80px">
        <el-row>
          <el-col :span="8">
            <el-form-item label="代号" prop="code">
              <el-input v-model="formMaterialList.code"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="名称" prop="name">
              <el-input v-model="formMaterialList.name"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="计算方向" prop="calculationDirection">
              <el-input v-model="formMaterialList.calculationDirection"></el-input>
            </el-form-item>
          </el-col>
          <!-- <el-col :span="8">
              <el-form-item label="规格" prop="Spec">
                <el-input v-model="formMaterialList.Spec"></el-input>
              </el-form-item>
            </el-col> -->
        </el-row>

        <el-row>
          <el-col :span="8">
            <el-form-item label="长" prop="length">
              <el-input v-model="formMaterialList.length"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="宽" prop="width">
              <el-input v-model="formMaterialList.width"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="高" prop="height">
              <el-input v-model="formMaterialList.height"></el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="8">
            <el-form-item label="材质" prop="quantity">
              <el-input v-model="formMaterialList.quantity"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="单位" prop="unit">
              <el-input v-model="formMaterialList.unit"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="颜色" prop="color">
              <el-input v-model="formMaterialList.color"></el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="8">
            <el-form-item label="单重" prop="weight">
              <el-input v-model="formMaterialList.weight"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="用量" prop="stitch">
              <el-input v-model="formMaterialList.stitch"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="副单位" prop="deputiUnits">
              <el-input v-model="formMaterialList.deputiUnits"></el-input>
            </el-form-item>
          </el-col>
        </el-row>



      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="handleSubmitMaterialList">确定</el-button>
        <el-button @click="openMaterialList">取消</el-button>
      </div>
    </el-dialog>

    <!-- 订单 -->
    <el-dialog :title="title" :visible.sync="open" width="1000px" append-to-body>
      <el-form ref="form" :disabled="this.form.status == '审核通过'" :model="form" label-width="100px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="订单编号" prop="orderNo">
              <el-input style="width: 240px;" :disabled="this.title == '查看订单'" v-model="form.orderNo"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="类型" prop="orderType">
              <el-select style="width: 240px;" :disabled="this.title == '查看订单'" v-model="form.orderType">
                <el-option label="外销" value="外销"></el-option>
                <el-option label="内销" value="内销"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="合同号" prop="contractNo">
              <el-input style="width: 240px;" :disabled="this.title == '查看订单'" v-model="form.contractNo"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="客户合同号" prop="customerContractNo">
              <el-input style="width: 240px;" :disabled="this.title == '查看订单'"
                v-model="form.customerContractNo"></el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="订单日期" prop="orderDate">
              <el-date-picker style="width: 240px;" :disabled="this.title == '查看订单'" type="date" placeholder="选择日期"
                v-model="form.orderDate"></el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="客户名称" prop="customer">
              <el-input style="width: 240px;" :disabled="this.title == '查看订单'" v-model="form.customer"></el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="销售员" prop="saleman">
              <el-input style="width: 240px;" :disabled="this.title == '查看订单'" v-model="form.saleman"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="审核状态" prop="status">
              <el-select style="width: 240px;" :disabled="this.title == '查看订单'" v-model="form.status">
                <el-option label="待审核" value="待审核"></el-option>
                <el-option label="审核通过" value="审核通过"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <!-- <el-col :span="12">
            <el-form-item label="封口方式" :disabled="this.form.status == '审核通过'" prop="sealingType">
              <el-select style="width: 240px;" v-model="form.sealingType">
                <el-option label="无封口" value="无封口"></el-option>
                <el-option label="封口" value="封口"></el-option>
              </el-select>
            </el-form-item>
          </el-col> -->
        </el-row>
        
        <el-row>
          <el-col :span="12">
            <el-form-item label="是否特价" prop="isSpecialPrice">
              <el-select style="width: 240px;" v-model="form.isSpecialPrice">
                <el-option label="否" value="否"></el-option>
                <el-option label="是" value="是"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="合同金额" prop="totalAmount">
              <el-input style="width: 240px;" v-model="form.totalAmount"></el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <!--  <el-row>
          <el-col :span="12">
            <el-form-item label="打包方式" prop="packingType">
              <el-select style="width: 240px;" :disabled="this.form.status == '审核通过'" v-model="form.packingType">
                <el-option label="整箱" value="整箱"></el-option>
                <el-option label="散装" value="散装"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="材质要求" prop="materialRequirements">
              <el-input style="width: 240px;"  :disabled="this.form.status == '审核通过'" v-model="form.materialRequirements"></el-input>
            </el-form-item>
          </el-col>
        </el-row> -->

        <el-row>

        </el-row>

        <!-- <el-row>
          <el-col :span="12">
            <el-form-item label="正唛" prop="frontMarking">
              <ImageUpload :disabled="this.form.status == '审核通过'" v-model="form.frontMarking" :limit="1"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="侧唛" prop="backMarking">
              <ImageUpload :disabled="this.form.status == '审核通过'" v-model="form.backMarking" :limit="1"/>
            </el-form-item>
          </el-col>
        </el-row> -->

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确定</el-button>
        <el-button @click="cancel">取消</el-button>
      </div>
    </el-dialog>

    <!-- 任务单 -->
    <el-dialog :title="titleTask" :visible.sync="openTask" width="500px" append-to-body>
      <el-form ref="formTask" :model="formTask" label-width="100px">
        <el-form-item label="生成任务单号" prop="taskNo">
          <el-input v-model="formTask.taskNo" style="width: 240px;"></el-input>
        </el-form-item>
        <el-form-item label="任务日期" prop="taskDate">
          <el-date-picker type="date" placeholder="选择日期" style="width: 240px;"
            v-model="formTask.taskDate"></el-date-picker>
        </el-form-item>
        <el-form-item label="任务计划开始日期" prop="planStartDate">
          <el-date-picker type="date" placeholder="选择日期" style="width: 240px;"
            v-model="formTask.planStartDate"></el-date-picker>
        </el-form-item>
        <el-form-item label="任务计划结束日期" prop="planEndDate">
          <el-date-picker type="date" placeholder="选择日期" style="width: 240px;"
            v-model="formTask.planEndDate"></el-date-picker>
        </el-form-item>
        <el-form-item label="合同号" prop="contractNo">
          <el-input v-model="formTask.contractNo" style="width: 240px;"></el-input>
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input type="textarea" v-model="formTask.remark" style="width: 240px;"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitTask">确定</el-button>
        <el-button @click="cancelTask">取消</el-button>
      </div>
    </el-dialog>

    <!-- 任务单明细 -->
    <el-dialog :title="titleTaskDetail" :visible.sync="openTaskDetail" width="1000px" append-to-body>
      <el-form ref="formOrderDetail" :model="formOrderDetail" label-width="100px">
        <el-row>
          <el-col :span="8">
            <el-form-item label="代号" prop="code">
              <el-input v-model="formOrderDetail.code"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="名称" prop="name">
              <el-input v-model="formOrderDetail.name"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="规格" prop="Spec">
              <el-input v-model="formOrderDetail.Spec"></el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="8">
            <el-form-item label="客户货号" prop="customerNo">
              <el-input v-model="formOrderDetail.customerNo"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="产品类型" prop="productType">
              <el-select v-model="formOrderDetail.productType">
                <el-option label="密胺" value="密胺"></el-option>
                <el-option label="塑胶" value="塑胶"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="产品属性" prop="productAttributes">
              <el-input v-model="formOrderDetail.productAttributes"></el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="8">
            <el-form-item label="颜色" prop="color">
              <el-input v-model="formOrderDetail.color"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="单重" prop="weight">
              <el-input v-model="formOrderDetail.weight"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="贴花方式" prop="stitch">
              <el-select v-model="formOrderDetail.stitch">
                <el-option label="无贴花" value="无贴花"></el-option>
                <el-option label="有贴花" value="有贴花"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>

          <el-col :span="8">
            <el-form-item label="光粉型号" prop="marking">
              <el-input v-model="formOrderDetail.marking"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="原料型号" prop="stuff">
              <el-input v-model="formOrderDetail.stuff"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="磨具货号" prop="sharpenerType">
              <el-select v-model="formOrderDetail.sharpenerType">
                <el-option label="磨具1" value="磨具1"></el-option>
                <el-option label="磨具2" value="磨具2"></el-option>
                <el-option label="磨具3" value="磨具3"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="8">
            <el-form-item label="磨数" prop="sharpenerNumber">
              <el-input v-model="formOrderDetail.sharpenerNumber"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="预估生成数量" prop="estimateQuantity">
              <el-input v-model="formOrderDetail.estimateQuantity"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="宽放比例" prop="wideRatio">
              <el-input v-model="formOrderDetail.wideRatio"></el-input>
            </el-form-item>
          </el-col>


        </el-row>

        <el-row>
          <el-col :span="8">
            <el-form-item label="称粉重量" prop="brandingWeight">
              <el-input v-model="formOrderDetail.brandingWeight"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="班产量" prop="batchQuantity">
              <el-input v-model="formOrderDetail.batchQuantity"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="包装要求" prop="packageRequirements">
              <el-input v-model="formOrderDetail.packageRequirements"></el-input>
            </el-form-item>
          </el-col>
        </el-row>

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitTaskDetail">确定</el-button>
        <el-button @click="cancelTaskDetail">取消</el-button>
      </div>
    </el-dialog>


  </div>
</template>

<script>
import { Splitpanes, Pane } from "splitpanes";
import "splitpanes/dist/splitpanes.css";
import {ImageUpload} from "@/components/ImageUpload"

export default {
  components:{
  Splitpanes,
   Pane
 },
  name: "productionTasks",
  data() {
    return {
      
      openTap: false,
      titleTap: '',
      
      title:'',
      open: false,
      form: {},
      // 任务单
      openTask: false,
      formTask: {},
      titleTask: '',
      // 任务单明细
      openTaskDetail: false,
      formOrderDetail: {},
      titleTaskDetail: '',
      
      
      formOrderDetail:{},
      formImg:{},
      img:[],
      
      activeNameComment: "first",
      
      // 明细
      commdate: [{
        id: 1,
        code: 'VX-YL-10820-20',
        name: '圆形果盘',
        Spec: '0*0*0',
        customerNo: '123456',
        productType: '密胺',
        unit:'个',
        productAttributes:'',
        color:'',
        weight:'',
        stitch:'',
        amount: '24',
        batch:'',
        batchNumber:'',
        batchDate:'',
        expiryDate:'2024-08-11',
        img:[
        'https://img.alicdn.com/imgextra/i2/651297984/TB27uXWrVXXXXXqXpXXXXXXXXXX_!!651297984.jpg',
        'https://img.alicdn.com/imgextra/i4/651297984/TB2Je0JrVXXXXcbXpXXXXXXXXXX_!!651297984.jpg',
        'https://bpic.588ku.com/element_origin_min_pic/21/10/12/d89b38b9266c8905910961914f28891f.jpg'
       ]
      },{
        id: 2,
        code: 'VX-YL-10820-21',
        name: '圆托盘',
        Spec: '0*0*0',
        customerNo: '',
        productType: '密胺',
        unit:'个',
        productAttributes:'',
        color:'',
        weight:'',
        stitch:'',
        amount: '12',
        batch:'',
        batchNumber:'',
        batchDate:'',
        expiryDate:'2024-12-11',
        img:[
          'https://imgs.zsbeike.com/imgs/B/B01080/b01080.0607.5.jpg',
          'https://cbu01.alicdn.com/img/ibank/2018/042/316/9358613240_759519532.jpg',
          'https://cbu01.alicdn.com/img/ibank/2020/441/212/16826212144_156162224.jpg'
        ]
      },{
        id: 3,
        code: 'VX-YL-10820-22',
        name: '圆盘托盘',
        Spec: '0*0*0',
        customerNo: '',
        productType: '密胺',
        unit:'个',
        productAttributes:'',
        color:'',
        weight:'',
        stitch:'',
        amount: '12',
        batch:'',
        batchNumber:'',
        batchDate:'',
        expiryDate:'2024-12-11',
        img:[
          'https://img.alicdn.com/imgextra/i2/651297984/TB27uXWrVXXXXXqXpXXXXXXXXXX_!!651297984.jpg',
          'https://img.alicdn.com/imgextra/i4/651297984/TB2Je0JrVXXXXcbXpXXXXXXXXXX_!!651297984.jpg',
          'https://bpic.588ku.com/element_origin_min_pic/21/10/12/d89b38b9266c8905910961914f28891f.jpg'
        ]
      }],
      // 附件
      fileDate:[{
        fileNo: '产品A',
        fileName: '产品A.pdf',
        filePath: 'https://erpmes.oss-cn-beijing.aliyuncs.com/1610151142321.pdf',
        fileType: '产品说明'
      },{
        fileNo: '产品B',
        fileName: '产品B.pdf',
        filePath: 'https://erpmes.oss-cn-beijing.aliyuncs.com/1610151142321.pdf',
        fileType: '产品说明'
      },{
        fileNo: '产品C',
        fileName: '产品C.pdf',
        filePath: 'https://erpmes.oss-cn-beijing.aliyuncs.com/1610151142321.pdf',
        fileType: '产品说明'
      }],
       // 变更情况
      changeDate:[{
        changeNumber: '1',
        changeNo: '20210101001',
        changeDate: '2021-01-01',
        changeModifier: '业务员A',
        changeContent: '产品A的数量由100000改为120000'
      },{
        changeNumber: '2',
        changeNo: '20210101002',
        changeDate: '2021-01-02',
        changeModifier: '业务员B',
        changeContent: '产品A的数量由120000改为140000'
      },{
        changeNumber: '3',
        changeNo: '20210101003',
        changeDate: '2021-01-03',
        changeModifier: '业务员C',
        changeContent: '产品A的数量由140000改为160000'
      }],
     //quantity: [{}],
      // 物料清单设置
      materialData:[{ code: 'GF', name: '光粉', Spec: '25kg/袋', unit: '千克',weight: '25kg' },
      { code: 'YL', name: '原料', Spec: '标准', unit: '吨' },
      { code: 'OPP', name: 'OPP袋', Spec: '30×40cm', unit: '个' },
      ],
      
      title:'',
      open: false,
      activeNameOrder: "first",
      queryParams: {
        pageNum: 1,
        pageSize: 10,
      },
      showCard: true,
      orderdata: [],
      total: 0,
      loading: false,
      showSearch: true,
      taskDateList:[
        {
          orderNo: '123456',
          itemName: '产品A',
          contractNo: '123456',
          customerContractNo: '123456',
          orderDate: '2021-01-01',
          customer: '客户A',
          saleman: '业务员A',
          orderType: '外销',

          storageStatus: '未入库',
          deliveryStatus: '未发货',
          outboundStatus: '未出库',
          accountingStatus: '未记账',
          stopStatus: '未停止',
          status: '审核通过',
          reviewStatus: '待评审',
          taskNo: "20210101001",
          taskDate: "2021-01-01",
          planStartDate: "2021-01-01",
          planEndDate: "2021-01-31",
          contractNo: "20210101001",
          remark: "备注",
          isSpecialPrice: '否',
          totalAmount: '100000',
          
        },
        {
          orderNo: '123457',
          itemName: '产品B',
          contractNo: '123457',
          customerContractNo: '123457',
          orderDate: '2021-01-02',
          customer: '客户B',
          saleman: '业务员B',
          orderType: '外销',
          storageStatus: '未入库',
          deliveryStatus: '未发货',
          outboundStatus: '未出库',
          accountingStatus: '未记账',
          stopStatus: '未停止',
          status: '待审核',
          reviewStatus: '待评审',
          taskNo: "20210101002",
          taskDate: "2021-01-01",
          planStartDate: "2021-01-01",
          planEndDate: "2021-01-31",
          contractNo: "20210101002",
          remark: "备注",
          isSpecialPrice: '否',
          totalAmount: '50000',
        },
        {
          orderNo: '123458',
          itemName: '产品C',
          contractNo: '123458',
          customerContractNo: '123458',
          orderDate: '2021-01-03',
          customer: '客户C',
          saleman: '业务员C',
          orderType: '外销',
          storageStatus: '未入库',
          deliveryStatus: '未发货',
          outboundStatus: '未出库',
          accountingStatus: '未记账',
          stopStatus: '未停止',
          status: '待审核',
          reviewStatus: '待评审',
          taskNo: "20210101003",
          taskDate: "2021-01-01",
          planStartDate: "2021-01-01",
          planEndDate: "2021-01-31",
          contractNo: "20210101003",
          remark: "备注",
          isSpecialPrice: '否',
          totalAmount: '200000',
        },
      ],
      activeName: "first",
      taskDetailData: [
        {
          code: "123456",
          name: "产品名称",
          Spec: "规格",
          customerNo: "客户货号",
          productType: "产品类型",
          productAttributes: "产品属性",
          marking:"光粉1",
          stuff:'A1',
          sharpenerType:'磨具1',
          sharpenerNumber:'16',
          color: "颜色",
          weight: "单重",
          stitch: "贴花方式",
          estimateQuantity: 100,
          wideRatio: 10,
          packageRequirements: "包装要求",
          brandingWeight: 100,
          batchQuantity: 100,
        },
        {
          code: "456789",
          name: "产品名称",
          Spec: "规格",
          customerNo: "客户货号",
          productType: "产品类型",
          productAttributes: "产品属性",
          color: "颜色",
          marking: "光粉2",
          stuff: 'A3',
          sharpenerType: '磨具2',
          sharpenerNumber: '4',
          weight: "单重",
          stitch: "贴花方式",
          estimateQuantity: 100,
          wideRatio: 10,
          packageRequirements: "包装要求",
          brandingWeight: 100,
          batchQuantity: 100,
        },
        {
          code: "789123",
          name: "产品名称",
          Spec: "规格",
          customerNo: "客户货号",
          productType: "产品类型",
          productAttributes: "产品属性",
          color: "颜色",
          marking: "光粉1",
          stuff: 'A3',
          sharpenerType: '磨具3',
          sharpenerNumber: '4',
          weight: "单重",
          stitch: "贴花方式",
          estimateQuantity: 100,
          wideRatio: 10,
          packageRequirements: "包装要求",
          brandingWeight: 100,
          batchQuantity: 100,
        },
      ],
      loadingTaskDetail: false,
      taskNo: "",
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 物料清单
       // 物料清单
      titleMaterialList: '',
      openMaterial: false,
      formMaterialList: {},
      //订单BOM
      titleBOM: '',
      openBOM: false,
      formBOM: {},
     bomMappings: {
      lightFinger: { code: 'GF', name: '光粉', spec: '25kg/袋', unit: '千克',weight: '25kg' },
      rawMaterial: { code: 'YL', name: '原料', spec: '标准', unit: '吨' },
      paper: { code: 'HZ', name: '花纸', spec: 'A4尺寸', unit: '卷',brand:'' },
      box: { code: 'ZX', name: '纸箱', spec: '50×50×50cm', unit: '个' },
      barcode: { code: 'TM', name: '条码', spec: '标准', unit: '张' },
      oppBag: { code: 'OPP', name: 'OPP袋', spec: '30×40cm', unit: '个' },
      peBag: { code: 'PE', name: 'PE袋', spec: '20×30cm', unit: '个' },
      instruction: { code: 'SM', name: '说明书', spec: 'A5尺寸', unit: '份' },
      colorMark: { code: 'CB', name: '彩标', spec: '标准', unit: '张' },
      whitePaper: { code: 'BZ', name: '白纸', spec: 'A4尺寸', unit: '张' }
      },
    };
    
    },
    methods: {
      // 显示高亮
        rowClassName({ row }) {
          return row.taskNo == this.taskNo ? 'selected-row' : ''; // 判断是否选中
        },
      
      // 任务单明细
      handleTaskDetail(row) {
        this.titleTaskDetail = '任务单明细';
        this.openTaskDetail = true;
        this.formOrderDetail = row;
      },
      
      submitForm(){
        this.$refs.form.validate((valid) => {
          if (valid) {
            this.$message.success('提交成功!')
            this.open = false;
          }
        })
      },
      // 关闭弹窗
      cancel() {
        this.form = {};
        this.open = false;
      },
      // 关闭弹窗
      handleCloseTask() {
        this.formTask = {};
        this.openTask = false;
      },
      
       // 反审核
    handleDetail(row) {
      this.$confirm('确定反审核该订单？')
      .then(() =>{
        row.status = '待审核';
        this.$message.success('反审核成功!')  
      }).catch(() => {
        this.$message.error('取消反审核!')
      })
    },
    
    // 审核
    handleReview(row) {
      this.$confirm('确定审核该订单？')
      .then(() =>{
        row.status = '审核通过';
        this.$message.success('审核成功!')  
      }).catch(() => {
        this.$message.error('取消审核!')
      })
    },
      
      handleView(row){
        this.form = row;
        this.title = '查看订单';
        this.open = true;
      },
      
      handleViewOrder(row){
        this.viewOrder('查看订单需求')
      },
      viewOrder(val){
        if(val == "查看订单需求"){
          let result = this.commdate[0];
          this.commdate = [],
          this.commdate.push(result)
          this.openTap = true;
        }
      },
    // 新增物料
    handleAddMaterial() {
      this.titleMaterialList = '新增物料';
      this.openMaterial = true;
    },
    // 修改物料
    handleEditMaterial(row) {
      this.titleMaterialList = '修改物料';
      this.openMaterial = true;
      this.formMaterialList = row;
    },
    // 关闭物料
    openMaterialList() {
      this.formMaterialList = {};
      this.openMaterial = false;
    },
    // 删除物料
    handleDeleteMaterial(row) {
      this.$confirm('确定删除该物料？')
      .then(() =>{
        this.materialData.splice(this.materialData.indexOf(row), 1)
        this.$message.success('删除成功!')
      }).catch(() => {
        this.$message.error('取消删除!')
      })
    },
    // 物料提交
    handleSubmitMaterialList() {
      this.$refs.formMaterialList.validate((valid) => {
        if (valid) {
          if(this.titleMaterialList == '新增物料'){
            this.materialData.push(this.formMaterialList);
            this.$message.success('新增物料成功!')
          } else if(this.titleMaterialList == '修改物料'){
            this.materialData.splice(this.materialData.indexOf(this.formMaterialList), 1, this.formMaterialList);
            this.$message.success('修改物料成功!')
          }
          this.formMaterialList = {};
          this.openMaterial = false;
        }
    }) 
    },
    // 物料取消
    colseBOM() {
      this.openBOM = false;
    },
    // 生成订单BOM
    handleAddBOM() {
      this.openBOM = true;
      this.titleBOM = '生成订单BOM';
    },
    handleSubmitBOM() {
  // 生成唯一ID
  const generateId = () => Date.now().toString(36) + Math.random().toString(36).substr(2)
  // 遍历所有选中的BOM项
  Object.entries(this.formBOM).forEach(([key, value]) => {
    if (value && this.bomMappings[key]) {
      let bomItem = {
        ...this.bomMappings[key],
        id: generateId(),
        code: `${this.bomMappings[key].code}-${Math.floor(100 + Math.random() * 900)}`,
        quantity: 1, // 默认数量
        productAttributes: '',
        color: '',
        weight: '',
        stitch: '1',
        deputiUnits: '1',
        calculationDirection: '乘以数量'
      }
      
      // 处理光粉特殊字段
      if (key === 'lightFinger') {
        bomItem = {
          ...bomItem,
          code: this.formBOM.lightFingerCode || bomItem.code,  // 使用用户输入或默认值
          weight: this.formBOM.lightFingerWeight ? `${this.formBOM.lightFingerWeight}g` : '',
        }
      }
      // 处理原料特殊字段
      if (key === 'rawMaterial') {
        bomItem = {
          ...bomItem,
          code: this.formBOM.rawMaterialCode || bomItem.code,  // 使用用户输入或默认值
          weight: this.formBOM.rawMaterialWeight ? `${this.formBOM.rawMaterialWeight}g` : '',
        }
      }
      if (key === 'paper') {
        bomItem = {
          ...bomItem,
          brand: this.formBOM.paperCode || '',  // 使用用户输入或默认值
        }
      }
      if (key === 'box') {
        bomItem = {
          ...bomItem,
          spec: this.formBOM.boxCode || '',  // 使用用户输入或默认值
        }
      }
      
      // 检查是否已存在相同物料
      const exists = this.materialData.some(item => 
        item.name === bomItem.name && 
        item.Spec === bomItem.spec
      )
      
      if (!exists) {
        this.materialData.push({
          ...bomItem,
          Spec: bomItem.spec // 匹配原有字段名
        })
      }
    }
  })

  this.$message.success('BOM生成成功!')
  this.openBOM = false
  },
      handleProcurement() {
        this.$router.push("/produce/procurement")
      },
      handleQuery() {
      },
      resetQuery() {},
      handleAdd() {},
      handleUpdateTask(row) {
        this.titleTask = '修改任务单';
        this.openTask = true;
        this.formTask = row;
      },
      handleDeleteTask(row) {
           this.$confirm('确定删除该任务单？')
          .then(() =>{
             this.taskDateList.splice(this.taskDateList.indexOf(row), 1)
             this.$message.success('删除成功!') 
             }).catch(() => {
              this.$message.error('取消删除!')
              })
      },
      // 提交任务单
      cancelTask() {
        this.$refs.formTask.validate((valid) => {
          if (valid) {
            if(this.titleTask == '新增任务单'){
              this.taskDateList.push(this.formTask);
              this.$message.success('新增任务单成功!')
            } else if(this.titleTask == '修改任务单'){
              this.taskDateList.splice(this.taskDateList.indexOf(this.formTask), 1, this.formTask);
              this.$message.success('修改任务单成功!')
            }
            this.formTask = {};
            this.openTask = false;
          }
        })
      },
      // 关闭任务单
      cancelTask() {
        this.formTask = {};
        this.openTask = false;
      },
      showTab(row) {
        this.showCard = true;
        this.taskNo = row.taskNo;
      },
      handleDispatch() {
        this.$router.push("/produce/dispatchOrder")
      },
      handleProduce() {},
      handleTaskDetailUpdate(row) {
        this.titleTaskDetail = '修改任务单明细';
        this.openTaskDetail = true;
        this.formOrderDetail = row;
      },
      handleTaskDetailDelete(row) {
          this.$confirm('确定删除该任务单明细？')
         .then(() =>{
            this.taskDetailData.splice(this.taskDetailData.indexOf(row), 1)
            this.$message.success('删除成功!')
          }).catch(() => {
            this.$message.error('取消删除!')
          })
      },
      // 关闭任务单明细
      cancelTaskDetail() {
        this.formOrderDetail = {};
        this.openTaskDetail = false;
      },
      // 任务单明细提交
      submitTaskDetail() {
        this.$refs.formOrderDetail.validate((valid) => {
          if (valid) {
            if(this.titleTaskDetail == '新增任务单明细'){
              this.taskDetailData.push(this.formOrderDetail);
              this.$message.success('新增任务单明细成功!')
            } else if(this.titleTaskDetail == '修改任务单明细'){
              this.taskDetailData.splice(this.taskDetailData.indexOf(this.formOrderDetail), 1, this.formOrderDetail);
              this.$message.success('修改任务单明细成功!')
            }
            this.formOrderDetail = {};
            this.openTaskDetail = false;
          }
        })
      },
      getList() {},
      // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.noticeId)
      this.single = selection.length!=1
      this.multiple = !selection.length
    },
    handleImgClick(row){
      this.img = row.img;
    },
    }
  }
</script>
<style>
.selected-row {
  background-color: yellow !important;
  /* 选中行的背景颜色 */
}
</style>
